/**
 * 
 */
package co.gov.medellin.sdep.sisdep.gestion.service;

import java.util.Date;
import java.util.List;

import co.gov.medellin.sdep.sisdep.gestion.exception.EstConceptoException;
import co.gov.medellin.sdep.sisdep.gestion.exception.EstConceptoRuntimeException;
import co.gov.medellin.sdep.sisdep.gestion.exception.descriptor.EstConceptoMessageDescriptor;
import co.gov.medellin.sdep.sisdep.common.message.MessageDescriptorConstant;
import co.gov.medellin.sdep.sisdep.common.service.BaseService;
import co.gov.medellin.sdep.sisdep.model.EstConcepto;
import co.gov.medellin.sdep.sisdep.model.dao.impl.IEstConceptoDAOT;

/**
 * @author Usuario
 *
 */
public class EstConceptoServiceImpl extends BaseService implements IEstConceptoService {

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                 init()
	//----------------------------------------------------------------------

	/**
	 * default serial version
	 */
	private static final long serialVersionUID = 1L;
	/** */
	private IEstConceptoDAOT estConceptoDAO;

	/**
	 * 
	 */
	public EstConceptoServiceImpl() {
	}

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                  end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                     init()
	//----------------------------------------------------------------------

	/**
	 * 
	 */
	public void insert(EstConcepto estConcepto) throws EstConceptoException {
		try{
			estConcepto.setUsuarioCrea(getPrincipalUser());			
			getEstConceptoDAO().insert(estConcepto);
		}catch (Exception e) {
			Object [] infoError = {
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new EstConceptoException(new EstConceptoMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new EstConceptoException(new EstConceptoMessageDescriptor(MessageDescriptorConstant.SAVE), infoError, e);
			}
		}
	}
	
	/**
	 * 
	 */
	public void insertDetalle(EstConcepto estConcepto) throws EstConceptoException {
		try{
			estConcepto.setUsuarioCrea(getPrincipalUser());			
			getEstConceptoDAO().insertDetalle(estConcepto);
		}catch (Exception e) {
			Object [] infoError = {
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new EstConceptoException(new EstConceptoMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new EstConceptoException(new EstConceptoMessageDescriptor(MessageDescriptorConstant.SAVE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void update(EstConcepto estConcepto) throws EstConceptoException {
		try{
			estConcepto.setUsuarioModifica(getPrincipalUser());			
			getEstConceptoDAO().update(estConcepto);
		}catch (Exception e) {
			Object [] infoError = {
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new EstConceptoRuntimeException(new EstConceptoMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new EstConceptoRuntimeException(new EstConceptoMessageDescriptor(MessageDescriptorConstant.UPDATE), infoError, e);
			}
		}
	}
	
	/**
	 * 
	 */
	public final void updateDetalle(EstConcepto estConcepto) throws EstConceptoException {
		try{
			estConcepto.setUsuarioModifica(getPrincipalUser());			
			getEstConceptoDAO().updateDetalle(estConcepto);
		}catch (Exception e) {
			Object [] infoError = {
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new EstConceptoRuntimeException(new EstConceptoMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new EstConceptoRuntimeException(new EstConceptoMessageDescriptor(MessageDescriptorConstant.UPDATE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void delete(EstConcepto estConcepto) throws EstConceptoException {
		try {
			estConcepto.setUsuarioModifica(getPrincipalUser());
			estConcepto.setFechaModifica(new Date());
			getEstConceptoDAO().delete(estConcepto);
		}catch (Exception e) {
			Object [] infoError = {
			};
			throw new EstConceptoRuntimeException(new EstConceptoMessageDescriptor(MessageDescriptorConstant.DELETE), infoError, e);
		}
	}

	/**
	 * @return 
	 * 
	 */
	public final List load(int start,int max, EstConcepto estConcepto) throws EstConceptoException {
		try{
			//return getEstConceptoDAO().getAllEstConceptoPaginated(start, max, criteria);
			return getEstConceptoDAO().load();
		}catch (Exception e) {
			Object [] infoError = null;
			throw new EstConceptoRuntimeException(new EstConceptoMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}
	
	/**
	 * @return 
	 * 
	 */
	public final List loadByIdEstudio(int start,int max, EstConcepto estConcepto) throws EstConceptoException {
		try{
			//return getEstConceptoDAO().getAllEstConceptoPaginated(start, max, criteria);
			return getEstConceptoDAO().loadByIdEstudio(estConcepto);
		}catch (Exception e) {
			Object [] infoError = null;
			throw new EstConceptoRuntimeException(new EstConceptoMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}
	
	/**
	 * @return 
	 * 
	 */
	public final List loadDetalleConcepto(int start,int max, EstConcepto estConcepto) throws EstConceptoException {
		try{
			//return getEstConceptoDAO().getAllEstConceptoPaginated(start, max, criteria);
			return getEstConceptoDAO().loadDetalleConcepto(estConcepto);
		}catch (Exception e) {
			Object [] infoError = null;
			throw new EstConceptoRuntimeException(new EstConceptoMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}
	/**
	 * @return 
	 * 
	 */
	public final List loadClasificacion(int start,int max, EstConcepto estConcepto) throws EstConceptoException {
		try{
			//return getEstConceptoDAO().getAllEstConceptoPaginated(start, max, criteria);
			return getEstConceptoDAO().loadClasificacion();
		}catch (Exception e) {
			Object [] infoError = null;
			throw new EstConceptoRuntimeException(new EstConceptoMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}

	/**
	 * 
	 */
	public final EstConcepto get(long id) throws EstConceptoException {
		try{
			return getEstConceptoDAO().findByPrimaryKey(id);
		}catch (Exception e) {
			Object [] infoError = {new Long(id)};
			throw new EstConceptoRuntimeException(new EstConceptoMessageDescriptor(MessageDescriptorConstant.GET), infoError, e);
		}
	}

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                      end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- getters and setters                                         init()
	//----------------------------------------------------------------------

	/**
	 * @author Usuario
	 *
	 */
	public IEstConceptoDAOT getEstConceptoDAO() {
		return estConceptoDAO;
	}

	/**
	 * @author Usuario
	 *
	 */
	public void setEstConceptoDAO(IEstConceptoDAOT estConceptoDAO) {
		this.estConceptoDAO = estConceptoDAO;
	}

	//----------------------------------------------------------------------
	//--- getters and setters                                          end()
	//----------------------------------------------------------------------

}
